package chpt02;

public class StringDemo02 {

	public static void main(String[] args) {
		String str1 = "hello";
		char[] chars = str1.toCharArray(); // 将字符串变为字符数组
		System.out.print("字符数组：");
		for (char e : chars) {
			System.out.print(e + "\t");
		}
		System.out.println();
		String str2 = new String(chars); // 将全部字符数组变为String
		String str3 = new String(chars, 0, 3); // 将部分字符数组变为String
		System.out.println("str2: " + str2);
		System.out.println("str3: " + str3);
		// 取出字符串第2个字符
		System.out.println("指定位置字符：" + str1.charAt(1));
		System.out.println("str1长度：" + str1.length());
		System.out.println("查找o: " + str1.indexOf("o"));
		System.out.println("从指定位置查找l：" + str1.indexOf("l", 3));
		System.out.println("查找x：" + str1.indexOf("x"));
	}
}
